home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / xpk_source / test / testmemunpack.c < prev    next >
C/C++ Source or Header  |  1998-08-27  |  2KB  |  99 lines

  1. #define NAME        "testMemUnpack"
  2. #define DISTRIBUTION    "(Freeware) "
  3. #define REVISION    "3"
  4. #define SDI_ENDCODE_NOCTRLC
  5.  
  6. /* Programmheader
  7.  
  8.     Name:        testMemUnpack
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    tests Xpk Pack function
  12.     Compileropts:    -
  13.     Linkeropts:    -l xpkmaster amiga
  14.  
  15.  1.1   06.12.96 : fixed for new includes, added new WriteXpkFib
  16.  1.2   15.04.97 : removed WriteXpkFib.c
  17.  1.3   28.11.97 : moved chunk-hook into include file
  18. */
  19.  
  20. #include <proto/exec.h>
  21. #include <proto/dos.h>
  22. #include <proto/xpkmaster.h>
  23. #include <exec/memory.h>
  24. #include "SDI_defines.h"
  25. #include "chunkhook.c"
  26.  
  27. struct Library        *XpkBase        = 0;
  28. ULONG            DosVersion        = 37;
  29. STRPTR            ibuf            = 0,
  30.             obuf            = 0;
  31. ULONG            ibuflen            = 0,
  32.             obuflen            = 0;
  33. BPTR            fh            = 0;
  34. struct RDArgs        *rda            = 0;
  35. struct FileInfoBlock    *fib            = 0;
  36. struct XpkFib        *xfib            = 0;
  37.  
  38. #define PARAM "FROM/A,TO"
  39.  
  40. void main(void)
  41. {
  42.   UBYTE errbuf[XPKERRMSGSIZE+1];
  43.   ULONG olen;
  44.   struct {
  45.     STRPTR from;
  46.     STRPTR to;
  47.   } args = {0,0};
  48.  
  49.   if(!(rda = ReadArgs(PARAM, (LONG *) &args, 0)) ||
  50.   !(xfib = (struct XpkFib *) AllocMem(sizeof(struct XpkFib), MEMF_ANY|MEMF_CLEAR)) ||
  51.   !(XpkBase = OpenLibrary(XPKNAME, 0)) ||
  52.   !(fh = Open(args.from, MODE_OLDFILE)) ||
  53.   !(fib = (struct FileInfoBlock *) AllocDosObject(DOS_FIB, 0)) ||
  54.   !(ExamineFH(fh, fib)) ||
  55.   !(ibuf = (STRPTR) AllocMem(fib->fib_Size, MEMF_ANY)) ||
  56.   Read(fh, ibuf, fib->fib_Size) != fib->fib_Size)
  57.     End(RETURN_FAIL);
  58.  
  59.   ibuflen = fib->fib_Size;
  60.   Close(fh); fh = 0;
  61.  
  62.   if(XpkExamineTags(xfib, XPK_InBuf, ibuf, XPK_InLen, ibuflen,
  63.     XPK_GetError, errbuf, TAG_DONE))
  64.   {
  65.     STRPTR a = errbuf;
  66.     VPrintf("Can't XpkExamine: %s\n", &a);
  67.     End(RETURN_FAIL);
  68.   }
  69.  
  70.   if(XpkUnpackTags(XPK_InBuf, ibuf, XPK_InLen, ibuflen,
  71.     XPK_GetOutBuf, &obuf, XPK_GetOutBufLen, &obuflen,
  72.     XPK_GetOutLen, &olen, XPK_GetError, errbuf,
  73.     XPK_PassThru, 1, XPK_ChunkHook, &chunkhook, TAG_DONE))
  74.   {
  75.     STRPTR a = errbuf;
  76.     VPrintf("Can't XpkUnpack: %s\n", &a);
  77.     End(RETURN_FAIL);
  78.   }
  79.  
  80.   if(args.to)
  81.     if(!(fh = Open(args.to, MODE_NEWFILE)) ||
  82.     Write(fh, obuf, olen) != olen)
  83.       End(RETURN_FAIL);
  84.  
  85.   End(RETURN_OK);
  86. }
  87.  
  88. void end(void)
  89. {
  90.   if(fh)    Close(fh);
  91.   if(xfib)    FreeMem(xfib, sizeof(struct XpkFib));
  92.   if(XpkBase)    CloseLibrary(XpkBase);
  93.   if(fib)    FreeDosObject(DOS_FIB, fib);
  94.   if(rda)    FreeArgs(rda);
  95.   if(ibuf)    FreeMem(ibuf, ibuflen);
  96.   if(obuf)    FreeMem(obuf, obuflen);
  97. }
  98.  
  99.